import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

void main() {
  runApp(MaterialApp(home: TextHomePage()));
}

class TextHomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return TextHomePageState();
  }
}

class TextHomePageState extends State {
  int?selectedValue;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Text 讲解"),
      ),
      body: Center(
        child: DropdownButton<int>(
          items: [
            DropdownMenuItem(
              child: Text("item1"),
              value: 1,
            ),
            DropdownMenuItem(
              child: Text("item2"),
              value: 2,
            ),
            DropdownMenuItem(
              child: Text("item3"),
              value: 3,
            )
          ],
          hint: Text("下拉按钮"), // 下拉按钮的文字
          disabledHint: Text("禁用下拉按钮"),
          style: TextStyle(fontSize: 22, color: Colors.green), // 按钮文字样式
          value: selectedValue, // 按钮默认显示弹框列表的哪个 item，和 DropdownMenuItem 的 value 相对应
          // 选了某个选项时触发
          onChanged: (selected) {
            print("_MyHomePageState - build onChanged $selected");
            setState(() {
              selectedValue = selected;
            });
          },
          onTap: () {
            print("_MyHomePageState - build 按钮点击");
          },
        ),
      ),
    );
  }
}
